home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Typography Samples / Dave’s Fab Samples ƒ / Kerning Adjustments.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-18  |  2.8 KB  |  95 lines  |  [TEXT/KAHL]

  1. /****************************************************************************************************
  2.     6/96 bob    Updated #includes to support changed GX Library names.
  3.     
  4.     ©1990 - 1996  Apple Computer, Inc.
  5.     All rights reserved.
  6. ****************************************************************************************************/
  7. #include <Types.h>
  8. #include <QuickDraw.h>
  9. #include <Fonts.h>
  10. #include <Windows.h>
  11. #include <Menus.h>
  12. #include <SegLoad.h>
  13. #include <Memory.h>
  14. #include <Desk.h>
  15.  
  16. #include <GXGraphics.h>
  17. #include "GraphicsLibraries.h"
  18. #include <GXEnvironment.h>
  19.  
  20. #include <GXTypes.h>
  21. #include <GXLayout.h>
  22. #include "LayoutLibrary.h"
  23.  
  24. #include "SampleInterface.h"
  25.  
  26. short MyStrLen(char *x);
  27. static short MyStrLen(x)
  28. char    *x;
  29.     {
  30.     short c = 0;
  31.     while (*x++) c++;
  32.     return c;
  33.     }    /* MyStrLen */
  34.  
  35. void KerningAdjustments(WindowPtr sampleWindow)
  36.     {
  37.     /* Variables */
  38.     char                *myString = "WAVE AWAY.";
  39.     gxGlyphcode            glyphcodes[20];
  40.     gxKerningAdjustment    gxKerningAdjustment;
  41.     gxLayoutOffsetState    offsetState;
  42.     gxPoint                myPoint;
  43.     gxRunControls            gxRunControls;
  44.     gxShape                layout;
  45.     short                len, level = 0;
  46.     gxStyle                myStyle;
  47.     unsigned short        firstGlyph, secondGlyph;
  48.     gxViewPort            aViewPort;
  49.     
  50.     /* Initialization */
  51.     
  52.     myPoint.x = ff(30);
  53.     myPoint.y = ff(50);
  54.     
  55.     aViewPort = GXNewWindowViewPort(sampleWindow);
  56.     SetDefaultViewPort(aViewPort);
  57.     
  58.     len = MyStrLen(myString);
  59.     InitializeRunControls(&gxRunControls);
  60.     
  61.     myStyle = NewLayoutStyle((char *) "\pHoefler Text", ff(60), 0, nil, nil, 0, nil);
  62.     
  63.     layout = GXNewLayout(
  64.         1, &len, (void *) &myString,
  65.         1, &len, &myStyle,
  66.         1, &len, &level,
  67.         nil, &myPoint);
  68.     GXDrawShape(layout);
  69.     
  70.     GXGetLayoutGlyphs(layout, glyphcodes, nil, nil, nil, nil, nil, nil);
  71.     GXGetOffsetGlyphs(layout, 1, false, &offsetState, &firstGlyph, &secondGlyph);
  72.     /* The "-1"s in the following lines convert from the 1-based space returned by GXGetOffsetGlyphs
  73.             into the zero-based space needed for array references. */
  74.     gxKerningAdjustment.firstGlyph = glyphcodes[firstGlyph - 1];
  75.     gxKerningAdjustment.secondGlyph = glyphcodes[secondGlyph - 1];
  76.     gxKerningAdjustment.crossStreamFactors.scaleFactor = 0;
  77.     gxKerningAdjustment.crossStreamFactors.adjustmentPointSizeFactor = 0;
  78.     
  79.     gxKerningAdjustment.withStreamFactors.scaleFactor = -(fract1 / 2);
  80.     gxKerningAdjustment.withStreamFactors.adjustmentPointSizeFactor = 0;
  81.     GXSetStyleRunKerningAdjustments(myStyle, 1, &gxKerningAdjustment);
  82.     GXMoveShape(layout, 0, ff(75));
  83.     GXDrawShape(layout);
  84.     
  85.     gxKerningAdjustment.withStreamFactors.scaleFactor = -fract1;
  86.     gxKerningAdjustment.withStreamFactors.adjustmentPointSizeFactor = fixed1 / 2;
  87.     GXSetStyleRunKerningAdjustments(myStyle, 1, &gxKerningAdjustment);
  88.     GXMoveShape(layout, 0, ff(75));
  89.     GXDrawShape(layout);
  90.     
  91.     GXDisposeShape(layout);
  92.     GXDisposeStyle(myStyle);
  93.     GXDisposeViewPort(aViewPort);
  94.     }    /* main */
  95.